%     VIRTUAL HC - программа для получения эффективных свойств сотовых заполнителей
%     Copyright (C) 2018-2020  Михаил Козлов
%     Сайт проекта: <http://www.fastenerdoctor.ru/>
%     Адрес электронной почты для связи с разработчиком:
%     <doctor.fastener@gmail.com>
% 
%     Эта программа является свободным программным обеспечением: Вы можете
%     распространять ее и/или изменять, соблюдая условия Универсальной общественной
%     лицензии GNU, опубликованной Фондом свободного программного обеспечения,
%     либо редакции 3, либо (на Ваше усмотрение) любой редакции, выпущенной позже.
% 
%     Эта программа распространяется в надежде на то, что она окажется полезной,
%     но БЕЗ КАКИХ-ЛИБО ГАРАНТИЙ, включая даже подразумеваемую гарантию ТОВАРНОЙ ПРИГОДНОСТИ,
%     либо ПРИГОДНОСТИ ДЛЯ ОПРЕДЕЛЕННЫХ ЦЕЛЕЙ. Ознакомьтесь с Универсальной общественной
%     лицензией GNU для получения более подробной информации.
% 
%     Вы должны были получить копию Универсальной общественной лицензии GNU
%     вместе с этой программой. Если Вы ее не получили, то перейдите по адресу:
%     <http://www.gnu.org/licenses/>.
% 
%     This program is free software: you can redistribute it and/or modify
%     it under the terms of the GNU General Public License as published by
%     the Free Software Foundation, either version 3 of the License, or
%     (at your option) any later version.
% 
%     This program is distributed in the hope that it will be useful,
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
%     GNU General Public License for more details.
% 
%     You should have received a copy of the GNU General Public License
%     along with this program.  If not, see <https://www.gnu.org/licenses/>.

function RVE_Frame_Solid = Construct_RVE_Solid(RVE_Frame_Shell, Foil_Thickness, RVE_Type)

global ErrCode;

fprintf (1, 'Создание базовых точек для твердотельной ячейки...      ');

RVE_Frame_Solid = zeros(47,2);

switch RVE_Type
    
    case 'TYPE_A'
        
        Offset_1 = [-RVE_Frame_Shell(2,2)/norm(RVE_Frame_Shell(2,:) - RVE_Frame_Shell(6,:)), (RVE_Frame_Shell(2,1) - RVE_Frame_Shell(6,1))/norm(RVE_Frame_Shell(2,:) - RVE_Frame_Shell(6,:))];
        Offset_2 = [-RVE_Frame_Shell(2,2)/norm(RVE_Frame_Shell(2,:) - RVE_Frame_Shell(6,:)), -(RVE_Frame_Shell(2,1) - RVE_Frame_Shell(6,1))/norm(RVE_Frame_Shell(2,:) - RVE_Frame_Shell(6,:))];
        
        RVE_Frame_Solid(1,:) = RVE_Frame_Shell(1,:);
        RVE_Frame_Solid(2,:) = Intersect_Lines(RVE_Frame_Shell(2,:), RVE_Frame_Shell(3,:), RVE_Frame_Shell(6,:) - Offset_1*Foil_Thickness/2, RVE_Frame_Shell(2,:) - Offset_1*Foil_Thickness/2);
        RVE_Frame_Solid(3,:) = [0, RVE_Frame_Shell(1,2)];
        RVE_Frame_Solid(4,:) = Intersect_Lines(RVE_Frame_Shell(2,:), RVE_Frame_Shell(3,:), RVE_Frame_Shell(3,:) + Offset_2*Foil_Thickness/2, RVE_Frame_Shell(7,:) + Offset_2*Foil_Thickness/2);
        RVE_Frame_Solid(5,:) = RVE_Frame_Shell(4,:);
        RVE_Frame_Solid(6,:) = Intersect_Lines(RVE_Frame_Shell(2,:) + [0, Foil_Thickness], RVE_Frame_Shell(3,:) + [0, Foil_Thickness], RVE_Frame_Shell(2,:) + Offset_1*Foil_Thickness/2, RVE_Frame_Shell(6,:) + Offset_1*Foil_Thickness/2);
        RVE_Frame_Solid(7,:) = [0, RVE_Frame_Shell(1,2) + Foil_Thickness];
        RVE_Frame_Solid(8,:) = Intersect_Lines(RVE_Frame_Shell(2,:) + [0, Foil_Thickness], RVE_Frame_Shell(3,:) + [0, Foil_Thickness], RVE_Frame_Shell(3,:) - Offset_2*Foil_Thickness/2, RVE_Frame_Shell(7,:) - Offset_2*Foil_Thickness/2);
        RVE_Frame_Solid(9,:) = [RVE_Frame_Shell(5,1), RVE_Frame_Shell(5,2) - Foil_Thickness];
        RVE_Frame_Solid(10,:) = RVE_Frame_Shell(5,:);
        RVE_Frame_Solid(11,:) = [RVE_Frame_Shell(5,1), RVE_Frame_Shell(5,2) + Foil_Thickness];
        RVE_Frame_Solid(12,:) = Intersect_Lines(RVE_Frame_Shell(5,:) + [0, -Foil_Thickness], RVE_Frame_Shell(6,:) + [0, -Foil_Thickness], RVE_Frame_Shell(2,:) - Offset_1*Foil_Thickness/2, RVE_Frame_Shell(6,:) - Offset_1*Foil_Thickness/2);
        RVE_Frame_Solid(13,:) = Intersect_Lines(RVE_Frame_Shell(6,:), RVE_Frame_Shell(7,:), RVE_Frame_Shell(6,:) + Offset_2*Foil_Thickness/2, RVE_Frame_Shell(10,:) + Offset_2*Foil_Thickness/2);
        RVE_Frame_Solid(14,:) = Intersect_Lines(RVE_Frame_Shell(5,:) + [0, Foil_Thickness], RVE_Frame_Shell(6,:) + [0, Foil_Thickness], RVE_Frame_Shell(6,:) - Offset_2*Foil_Thickness/2, RVE_Frame_Shell(10,:) - Offset_2*Foil_Thickness/2);
        RVE_Frame_Solid(15,:) = [0, 0];
        RVE_Frame_Solid(16,:) = Intersect_Lines(RVE_Frame_Shell(7,:) + [0, -Foil_Thickness], RVE_Frame_Shell(8,:) + [0, -Foil_Thickness], RVE_Frame_Shell(3,:) + Offset_2*Foil_Thickness/2, RVE_Frame_Shell(7,:) + Offset_2*Foil_Thickness/2);
        RVE_Frame_Solid(17,:) = Intersect_Lines(RVE_Frame_Shell(6,:), RVE_Frame_Shell(7,:), RVE_Frame_Shell(7,:) - Offset_1*Foil_Thickness/2, RVE_Frame_Shell(11,:) - Offset_1*Foil_Thickness/2);
        RVE_Frame_Solid(18,:) = Intersect_Lines(RVE_Frame_Shell(7,:) + [0, Foil_Thickness], RVE_Frame_Shell(8,:) + [0, Foil_Thickness], RVE_Frame_Shell(7,:) + Offset_1*Foil_Thickness/2, RVE_Frame_Shell(11,:) + Offset_1*Foil_Thickness/2);
        RVE_Frame_Solid(19,:) = [RVE_Frame_Shell(8,1), RVE_Frame_Shell(8,2) - Foil_Thickness];
        RVE_Frame_Solid(20,:) = RVE_Frame_Shell(8,:);
        RVE_Frame_Solid(21,:) = [RVE_Frame_Shell(8,1), RVE_Frame_Shell(8,2) + Foil_Thickness];
        RVE_Frame_Solid(22,:) = Intersect_Lines(RVE_Frame_Shell(10,:) + [0, -Foil_Thickness], RVE_Frame_Shell(11,:) + [0, -Foil_Thickness], RVE_Frame_Shell(6,:) + Offset_2*Foil_Thickness/2, RVE_Frame_Shell(10,:) + Offset_2*Foil_Thickness/2);
        RVE_Frame_Solid(23,:) = [0, RVE_Frame_Shell(9,2) - Foil_Thickness];
        RVE_Frame_Solid(24,:) = Intersect_Lines(RVE_Frame_Shell(10,:) + [0, -Foil_Thickness], RVE_Frame_Shell(11,:) + [0, -Foil_Thickness], RVE_Frame_Shell(11,:) - Offset_1*Foil_Thickness/2, RVE_Frame_Shell(7,:) - Offset_1*Foil_Thickness/2);
        RVE_Frame_Solid(25,:) = RVE_Frame_Shell(9,:);
        RVE_Frame_Solid(26,:) = Intersect_Lines(RVE_Frame_Shell(10,:), RVE_Frame_Shell(11,:), RVE_Frame_Shell(6,:) - Offset_2*Foil_Thickness/2, RVE_Frame_Shell(10,:) - Offset_2*Foil_Thickness/2);
        RVE_Frame_Solid(27,:) = [0, RVE_Frame_Shell(9,2)];
        RVE_Frame_Solid(28,:) = Intersect_Lines(RVE_Frame_Shell(10,:), RVE_Frame_Shell(11,:), RVE_Frame_Shell(11,:) + Offset_1*Foil_Thickness/2, RVE_Frame_Shell(7,:) + Offset_1*Foil_Thickness/2);
        RVE_Frame_Solid(29,:) = RVE_Frame_Shell(12,:);
        
        RVE_Frame_Solid(30,:) = Project_Point_Line(RVE_Frame_Solid(6,:), RVE_Frame_Solid(2,:), RVE_Frame_Solid(12,:));
        RVE_Frame_Solid(31,:) = Project_Point_Line(RVE_Frame_Solid(6,:), RVE_Frame_Solid(2,:), RVE_Frame_Solid(3,:));
        RVE_Frame_Solid(32,:) = Project_Point_Line(RVE_Frame_Solid(8,:), RVE_Frame_Solid(3,:), RVE_Frame_Solid(4,:));
        RVE_Frame_Solid(33,:) = Project_Point_Line(RVE_Frame_Solid(8,:), RVE_Frame_Solid(4,:), RVE_Frame_Solid(16,:));
        RVE_Frame_Solid(34,:) = Intersect_Lines(RVE_Frame_Solid(10,:), RVE_Frame_Solid(13,:), RVE_Frame_Solid(12,:), RVE_Frame_Solid(14,:));
        RVE_Frame_Solid(35,:) = Project_Point_Line(RVE_Frame_Solid(12,:), RVE_Frame_Solid(6,:), RVE_Frame_Solid(13,:));
        RVE_Frame_Solid(36,:) = Project_Point_Line(RVE_Frame_Solid(14,:), RVE_Frame_Solid(13,:), RVE_Frame_Solid(22,:));
        RVE_Frame_Solid(37,:) = Intersect_Lines(RVE_Frame_Solid(17,:), RVE_Frame_Solid(20,:), RVE_Frame_Solid(16,:), RVE_Frame_Solid(18,:));
        RVE_Frame_Solid(38,:) = Project_Point_Line(RVE_Frame_Solid(16,:), RVE_Frame_Solid(8,:), RVE_Frame_Solid(17,:));
        RVE_Frame_Solid(39,:) = Project_Point_Line(RVE_Frame_Solid(18,:), RVE_Frame_Solid(17,:), RVE_Frame_Solid(24,:));
        RVE_Frame_Solid(40,:) = Project_Point_Line(RVE_Frame_Solid(22,:), RVE_Frame_Solid(14,:), RVE_Frame_Solid(26,:));
        RVE_Frame_Solid(41,:) = Project_Point_Line(RVE_Frame_Solid(22,:), RVE_Frame_Solid(26,:), RVE_Frame_Solid(27,:));
        RVE_Frame_Solid(42,:) = Project_Point_Line(RVE_Frame_Solid(24,:), RVE_Frame_Solid(27,:), RVE_Frame_Solid(28,:));
        RVE_Frame_Solid(43,:) = Project_Point_Line(RVE_Frame_Solid(24,:), RVE_Frame_Solid(18,:), RVE_Frame_Solid(28,:));
        RVE_Frame_Solid(44,:) = [RVE_Frame_Solid(1,1), RVE_Frame_Solid(30,2)];
        RVE_Frame_Solid(45,:) = [RVE_Frame_Solid(5,1), RVE_Frame_Solid(33,2)];
        RVE_Frame_Solid(46,:) = [RVE_Frame_Solid(25,1), RVE_Frame_Solid(40,2)];
        RVE_Frame_Solid(47,:) = [RVE_Frame_Solid(29,1), RVE_Frame_Solid(43,2)];
        RVE_Frame_Solid(48,:) = Intersect_Lines(RVE_Frame_Solid(7,:), RVE_Frame_Solid(15,:), RVE_Frame_Solid(35,:), RVE_Frame_Solid(38,:));
        RVE_Frame_Solid(49,:) = Intersect_Lines(RVE_Frame_Solid(15,:), RVE_Frame_Solid(23,:), RVE_Frame_Solid(36,:), RVE_Frame_Solid(39,:));
        
    case 'TYPE_B'
        
        Offset_1 = [-RVE_Frame_Shell(10,2)/norm(RVE_Frame_Shell(2,:) - RVE_Frame_Shell(10,:)), -(RVE_Frame_Shell(2,1) - RVE_Frame_Shell(10,1))/norm(RVE_Frame_Shell(2,:) - RVE_Frame_Shell(10,:))];
        Offset_2 = [-RVE_Frame_Shell(10,2)/norm(RVE_Frame_Shell(2,:) - RVE_Frame_Shell(10,:)), (RVE_Frame_Shell(2,1) - RVE_Frame_Shell(10,1))/norm(RVE_Frame_Shell(2,:) - RVE_Frame_Shell(10,:))];
        
        RVE_Frame_Solid(1,:) = RVE_Frame_Shell(9,:);
        RVE_Frame_Solid(2,:) = Intersect_Lines(RVE_Frame_Shell(9,:), RVE_Frame_Shell(10,:), RVE_Frame_Shell(10,:) + Offset_1*Foil_Thickness/2, RVE_Frame_Shell(2,:) + Offset_1*Foil_Thickness/2);
        RVE_Frame_Solid(3,:) = [0, RVE_Frame_Shell(9,2)];
        RVE_Frame_Solid(4,:) = Intersect_Lines(RVE_Frame_Shell(11,:), RVE_Frame_Shell(12,:), RVE_Frame_Shell(11,:) - Offset_2*Foil_Thickness/2, RVE_Frame_Shell(3,:) - Offset_2*Foil_Thickness/2);
        RVE_Frame_Solid(5,:) = RVE_Frame_Shell(12,:);
        RVE_Frame_Solid(6,:) = [RVE_Frame_Shell(9,1), RVE_Frame_Shell(9,2) + Foil_Thickness];
        RVE_Frame_Solid(7,:) = Intersect_Lines(RVE_Frame_Shell(9,:) + [0, Foil_Thickness], RVE_Frame_Shell(10,:) + [0, Foil_Thickness], RVE_Frame_Shell(10,:) - Offset_1*Foil_Thickness/2, RVE_Frame_Shell(2,:) - Offset_1*Foil_Thickness/2);
        RVE_Frame_Solid(8,:) = Intersect_Lines(RVE_Frame_Shell(11,:) + [0, Foil_Thickness], RVE_Frame_Shell(12,:) + [0, Foil_Thickness], RVE_Frame_Shell(3,:) + Offset_2*Foil_Thickness/2, RVE_Frame_Shell(11,:) + Offset_2*Foil_Thickness/2);
        RVE_Frame_Solid(9,:) = [RVE_Frame_Shell(12,1), RVE_Frame_Shell(12,2) + Foil_Thickness];
        RVE_Frame_Solid(10,:) = Intersect_Lines(RVE_Frame_Shell(2,:) + [0, -Foil_Thickness], RVE_Frame_Shell(3,:) + [0, -Foil_Thickness], RVE_Frame_Shell(2,:) + Offset_1*Foil_Thickness/2, RVE_Frame_Shell(10,:) + Offset_1*Foil_Thickness/2);
        RVE_Frame_Solid(11,:) = [0, -Foil_Thickness];
        RVE_Frame_Solid(12,:) = Intersect_Lines(RVE_Frame_Shell(2,:) + [0, -Foil_Thickness], RVE_Frame_Shell(3,:) + [0, -Foil_Thickness], RVE_Frame_Shell(3,:) - Offset_2*Foil_Thickness/2, RVE_Frame_Shell(11,:) - Offset_2*Foil_Thickness/2);
        RVE_Frame_Solid(13,:) = Intersect_Lines(RVE_Frame_Shell(2,:), RVE_Frame_Shell(3,:), RVE_Frame_Shell(2,:) - Offset_2*Foil_Thickness/2, RVE_Frame_Shell(6,:) - Offset_2*Foil_Thickness/2);
        RVE_Frame_Solid(14,:) = [0, 0];
        RVE_Frame_Solid(15,:) = Intersect_Lines(RVE_Frame_Shell(2,:), RVE_Frame_Shell(3,:), RVE_Frame_Shell(3,:) + Offset_1*Foil_Thickness/2, RVE_Frame_Shell(7,:) + Offset_1*Foil_Thickness/2);
        RVE_Frame_Solid(16,:) = Intersect_Lines(RVE_Frame_Shell(2,:) + [0, Foil_Thickness], RVE_Frame_Shell(3,:) + [0, Foil_Thickness], RVE_Frame_Shell(2,:) + Offset_2*Foil_Thickness/2, RVE_Frame_Shell(6,:) + Offset_2*Foil_Thickness/2);
        RVE_Frame_Solid(17,:) = [0, Foil_Thickness];
        RVE_Frame_Solid(18,:) = Intersect_Lines(RVE_Frame_Shell(2,:) + [0, Foil_Thickness], RVE_Frame_Shell(3,:) + [0, Foil_Thickness], RVE_Frame_Shell(3,:) - Offset_1*Foil_Thickness/2, RVE_Frame_Shell(7,:) - Offset_1*Foil_Thickness/2);
        RVE_Frame_Solid(19,:) = RVE_Frame_Shell(1,:);
        RVE_Frame_Solid(20,:) = RVE_Frame_Shell(4,:);
        RVE_Frame_Solid(21,:) = [RVE_Frame_Shell(5,1), RVE_Frame_Shell(5,2) - Foil_Thickness];
        RVE_Frame_Solid(22,:) = Intersect_Lines(RVE_Frame_Shell(5,:) + [0, -Foil_Thickness], RVE_Frame_Shell(6,:) + [0, -Foil_Thickness], RVE_Frame_Shell(2,:) - Offset_2*Foil_Thickness/2, RVE_Frame_Shell(6,:) - Offset_2*Foil_Thickness/2);
        RVE_Frame_Solid(23,:) = Intersect_Lines(RVE_Frame_Shell(7,:) + [0, -Foil_Thickness], RVE_Frame_Shell(8,:) + [0, -Foil_Thickness], RVE_Frame_Shell(3,:) + Offset_1*Foil_Thickness/2, RVE_Frame_Shell(7,:) + Offset_1*Foil_Thickness/2);
        RVE_Frame_Solid(24,:) = [RVE_Frame_Shell(8,1), RVE_Frame_Shell(8,2) - Foil_Thickness];
        RVE_Frame_Solid(25,:) = RVE_Frame_Shell(5,:);
        RVE_Frame_Solid(26,:) = Intersect_Lines(RVE_Frame_Shell(5,:), RVE_Frame_Shell(6,:), RVE_Frame_Shell(6,:) + Offset_2*Foil_Thickness/2, RVE_Frame_Shell(2,:) + Offset_2*Foil_Thickness/2);
        RVE_Frame_Solid(27,:) = [0, RVE_Frame_Shell(5,2)];
        RVE_Frame_Solid(28,:) = Intersect_Lines(RVE_Frame_Shell(7,:), RVE_Frame_Shell(8,:), RVE_Frame_Shell(3,:) - Offset_1*Foil_Thickness/2, RVE_Frame_Shell(7,:) - Offset_1*Foil_Thickness/2);
        RVE_Frame_Solid(29,:) = RVE_Frame_Shell(8,:);
        
        RVE_Frame_Solid(30,:) = Project_Point_Line(RVE_Frame_Solid(7,:), RVE_Frame_Solid(1,:), RVE_Frame_Solid(2,:));
        RVE_Frame_Solid(31,:) = Project_Point_Line(RVE_Frame_Solid(7,:), RVE_Frame_Solid(2,:), RVE_Frame_Solid(10,:));
        RVE_Frame_Solid(32,:) = Project_Point_Line(RVE_Frame_Solid(8,:), RVE_Frame_Solid(4,:), RVE_Frame_Solid(5,:));
        RVE_Frame_Solid(33,:) = Project_Point_Line(RVE_Frame_Solid(8,:), RVE_Frame_Solid(4,:), RVE_Frame_Solid(12,:));
        RVE_Frame_Solid(34,:) = Intersect_Lines(RVE_Frame_Solid(13,:), RVE_Frame_Solid(14,:), RVE_Frame_Solid(10,:), RVE_Frame_Solid(16,:));
        RVE_Frame_Solid(35,:) = Project_Point_Line(RVE_Frame_Solid(10,:), RVE_Frame_Solid(7,:), RVE_Frame_Solid(13,:));
        RVE_Frame_Solid(36,:) = Project_Point_Line(RVE_Frame_Solid(16,:), RVE_Frame_Solid(13,:), RVE_Frame_Solid(22,:));
        RVE_Frame_Solid(37,:) = Intersect_Lines(RVE_Frame_Solid(14,:), RVE_Frame_Solid(15,:), RVE_Frame_Solid(12,:), RVE_Frame_Solid(18,:));
        RVE_Frame_Solid(38,:) = Project_Point_Line(RVE_Frame_Solid(12,:), RVE_Frame_Solid(8,:), RVE_Frame_Solid(15,:));
        RVE_Frame_Solid(39,:) = Project_Point_Line(RVE_Frame_Solid(18,:), RVE_Frame_Solid(15,:), RVE_Frame_Solid(23,:));
        RVE_Frame_Solid(40,:) = Project_Point_Line(RVE_Frame_Solid(22,:), RVE_Frame_Solid(25,:), RVE_Frame_Solid(26,:));
        RVE_Frame_Solid(41,:) = Project_Point_Line(RVE_Frame_Solid(22,:), RVE_Frame_Solid(16,:), RVE_Frame_Solid(26,:));
        RVE_Frame_Solid(42,:) = Project_Point_Line(RVE_Frame_Solid(23,:), RVE_Frame_Solid(18,:), RVE_Frame_Solid(28,:));
        RVE_Frame_Solid(43,:) = Project_Point_Line(RVE_Frame_Solid(23,:), RVE_Frame_Solid(28,:), RVE_Frame_Solid(29,:));
        RVE_Frame_Solid(44,:) = [RVE_Frame_Solid(1,1), RVE_Frame_Solid(35,2)];
        RVE_Frame_Solid(45,:) = [RVE_Frame_Solid(5,1), RVE_Frame_Solid(38,2)];
        RVE_Frame_Solid(46,:) = [RVE_Frame_Solid(1,1), RVE_Frame_Solid(36,2)];
        RVE_Frame_Solid(47,:) = [RVE_Frame_Solid(5,1), RVE_Frame_Solid(39,2)];
        RVE_Frame_Solid(48,:) = Intersect_Lines(RVE_Frame_Solid(3,:), RVE_Frame_Solid(11,:), RVE_Frame_Solid(31,:), RVE_Frame_Solid(33,:));
        RVE_Frame_Solid(49,:) = Intersect_Lines(RVE_Frame_Solid(17,:), RVE_Frame_Solid(27,:), RVE_Frame_Solid(41,:), RVE_Frame_Solid(42,:));
        
    otherwise
        
        fprintf (1, '\nОшибка функции Construct_RVE_Solid: недопустимое значение параметра RVE_Type !\n');
        ErrCode = -1;
        return;
    
end

fprintf (1, 'OK!\n');
